package recharge

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeRatelistLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 汇率列表
func NewRechargeRatelistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeRatelistLogic {
	return &RechargeRatelistLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RechargeRatelistLogic) RechargeRatelist(req *types.RechargeRatelistRequest) (resp *types.RechargeRatelistResponse, err error) {
	list, err := l.svcCtx.AssetsRpc.PayRecharge.VirtualDicsList(l.ctx, &rpc.VirtualDicsListReq{})
	if err != nil {
		return nil, err
	}
	var respList []types.RechargeRatelist
	for _, v := range list.List {
		respList = append(respList, types.RechargeRatelist{
			CoinName: v.Coin_Name,
			Rate:     v.To_Rata,
			Icon:     v.Icon,
		})
	}

	return &types.RechargeRatelistResponse{
		RateList: respList,
	}, nil
}
